//package com.ruoyi.stock2.thread.aboutDownloadData;
//
//import java.io.IOException;
//import java.math.BigDecimal;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import com.ruoyi.stock2.domain.TRADEDATA200;
//import com.ruoyi.stock2.domain.STOCK;
//import com.ruoyi.stock2.domain.PriceCompAverage200;
//import com.ruoyi.stock2.service.IPriceCompAverage200Service;
//import com.ruoyi.stock2.service.ISTOCKService;
//import com.ruoyi.stock2.service.ITRADEDATA200Service;
//import org.jsoup.Jsoup;
//import org.jsoup.nodes.Document;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.util.StringUtils;
//import com.ruoyi.stock2.utils.DateUtils2;
//import com.ruoyi.stock2.utils.J2cache;
//import com.ruoyi.stock2.utils.NameAndValue;
//import net.oschina.j2cache.CacheChannel;
////下载新浪行情的业务逻辑
//@Service
//public class HqSinajsService {
//
//	@Autowired
//	ISTOCKService istockService;
//
//	@Autowired
//	ITRADEDATA200Service itradedata200Service;
//
//	@Autowired
//	BuildTrainService buildTrainService;
//
//	@Autowired
//	IPriceCompAverage200Service iPriceCompAverage200Service;
//
//
//
//	public void step1() {
//		//大盘指数下载行情，补齐均线，生成价格与均线比值，保存到j2cache
//		Map<String, Map<String, Object>> dapanzhishu_map_vol_price = hqsinajs("sz399001,sz399006,sh000001");
//		makeTradeData_PriceCompareAverage(dapanzhishu_map_vol_price);
//
//		//非大盘指数 下载行情，补齐均线，生成价格与均线比值（保存到表），[生成预测集（保存到表）需要大盘的价格与均线比值]
//		List<STOCK> stocks = istockService.selectSTOCKList(null);// 所有的股票单
//		StringBuilder tempString = new StringBuilder();
//		int jishuqi = 0;
//		for (STOCK stock : stocks) {
//
//			if(stock.getSymbol().startsWith("0")){
//				tempString.append("sz"+stock.getSymbol()).append(",");
//			}
//
//			if(stock.getSymbol().startsWith("3")){
//				tempString.append("sz"+stock.getSymbol()).append(",");
//			}
//
//			if(stock.getSymbol().startsWith("6")){
//				tempString.append("sh"+stock.getSymbol()).append(",");
//			}
//			jishuqi++;
//			if(jishuqi % 100 ==0){
//				long a = System.currentTimeMillis();
//				Map<String, Map<String, Object>> map_vol_price = hqsinajs(tempString.toString());
//				long b = System.currentTimeMillis();
//				System.out.println("访问新浪耗时："+(b-a)/1000+"秒， "+(b-a)+"毫秒");
//				makeTradeData_PriceCompareAverage(map_vol_price);
//				tempString.setLength(0);
//			}
//		}
//		if(tempString.length()>0){
//			Map<String, Map<String, Object>> map_vol_price = hqsinajs(tempString.toString());
//			makeTradeData_PriceCompareAverage(map_vol_price);
//		}
//	}
//	/*
//	 * 循环模型 根据createtime是当前日期查询记录，并标记模型的类型
//	 * 便于spark程序调用
//	 */
//	public void step2(Date fromDate) {
//		buildTrainService.from200saveToForetellResultTable(fromDate);
//	}
//
//	@SuppressWarnings("unchecked")
//	private void makeTradeData_PriceCompareAverage( Map<String, Map<String, Object>> map_vol_price ){
//
//		Map<String, Object> temp_net_price = map_vol_price.get("price");
//		Map<String, Object> temp_net_vol = map_vol_price.get("vol");
//		Map<String, Object> temp_net_date = map_vol_price.get("date");
//		Map<String, Object> temp_net_amount = map_vol_price.get("amount");
//		Map<String, Object> temp_net_open = map_vol_price.get("open");
//		Map<String, Object> temp_net_high = map_vol_price.get("high");
//		Map<String, Object> temp_net_low = map_vol_price.get("low");
//
//		//获取现在日期，如果hqsinajs获取的日期和现在对应不上，一定是停牌了
//		Date today = new Date();
//		String date = DateUtils2.formatDateToString(today, "yyyy-MM-dd");
//
//		CacheChannel cache;
//		try {
//			cache = J2cache.getInstance().getCache();
//
//			for (Map.Entry<String, Object> entry : temp_net_price.entrySet()) {
//				String symbol = entry.getKey();
//
//				String price = temp_net_price.get(symbol).toString();
//				double priced = Double.parseDouble(price);
//
//				String amount = temp_net_amount.get(symbol).toString();
//				double amountd = Double.parseDouble(amount);
//
//				String date_time = temp_net_date.get(symbol).toString();
//				//可以通过 date，price和 amount的值来判断是否停牌
//				if(!date.equals(date_time) || StringUtils.isEmpty(price) || priced == 0.0d || StringUtils.isEmpty(amount) || amountd == 0.0d){
//					System.out.println(symbol+" 停牌" + date_time + " priced=" + priced + " amount=" + amount);
//					continue;
//				}
//
//				String vol = temp_net_vol.get(symbol).toString();
//				String open = temp_net_open.get(symbol).toString();
//				String high = temp_net_high.get(symbol).toString();
//				String low = temp_net_low.get(symbol).toString();
//
//				TRADEDATA200 hq = new TRADEDATA200();
//				hq.setSymbol(symbol);
//				hq.setDatetime(DateUtils2.formatStringToDate(date_time,"yyyy-MM-dd"));
//				hq.setDateopenprice(new BigDecimal(open));
//				hq.setCloseprice(new BigDecimal(price));
//				hq.setHighprice(new BigDecimal(high));
//				hq.setLowprice(new BigDecimal(low));
//				hq.setVolume(new BigDecimal(vol).divide(new BigDecimal(100), 0, BigDecimal.ROUND_HALF_UP));
//				hq.setAmount(new BigDecimal(amount).divide(new BigDecimal(10000), 0, BigDecimal.ROUND_HALF_UP));
//				long a = System.currentTimeMillis();
//				//获取该股票的缓存200条集合,缓存中没有就现查，查后再插入
//				int f = cache.check("default", symbol+"_"+date_time);
//				List<TRADEDATA200> list200TradeData = null;
//				TRADEDATA200 tdkey = new TRADEDATA200(symbol, DateUtils2.formatStringToDate("2004-01-01","yyyy-MM-dd"));
//				if(f == 0) {
//					list200TradeData = itradedata200Service.get200ByKeyDateTimeDesc(tdkey);
//					cache.evict("default", symbol+"_"+date_time);
//					cache.set("default", symbol+"_"+date_time, list200TradeData);
//				}else {
//					list200TradeData = (List<TRADEDATA200>) cache.get("default", symbol+"_"+date_time).getValue();
//				}
//
//				//当前的股票的行情值加入集合
//				list200TradeData.add(0, hq);
//				tdkey.setDatetime(DateUtils2.formatStringToDate(date_time,"yyyy-MM-dd"));
//				long b = System.currentTimeMillis();
//				System.out.println("获取200交易记录耗时："+(b-a)/1000+"秒， "+(b-a)+"毫秒");
//				//完善当前股票的均价
//
//				completeVolumeAndaragPrice(list200TradeData, DateUtils2.formatStringToDate(date_time,"yyyy-MM-dd"));
//				long c = System.currentTimeMillis();
//				System.out.println("完善当前股票的均价耗时："+(c-b)/1000+"秒， "+(c-b)+"毫秒");
//
//				TRADEDATA200 key = new TRADEDATA200(symbol, DateUtils2.formatStringToDate(date_time,"yyyy-MM-dd"));
//				List<TRADEDATA200> tradeData1 = itradedata200Service.selectTRADEDATA200List(key);
//				if(tradeData1.size() != 0) {
//					itradedata200Service.updateTRADEDATA200(list200TradeData.get(0));
//				}else {
//					itradedata200Service.insertTRADEDATA200(list200TradeData.get(0));
//				}
//				long d = System.currentTimeMillis();
//				System.out.println("insertTRADEDATA耗时："+(d-c)/1000+"秒， "+(d-c)+"毫秒");
//				//完成当前股票价格与均线比值
//				PriceCompAverage200 priceCompareAverage200 = completePriceAverageComp(list200TradeData, tdkey);
//
//				long e = System.currentTimeMillis();
//				System.out.println("完成当前股票价格与均线比值耗时："+(e-d)/1000+"秒， "+(e-d)+"毫秒");
//
//				if(priceCompareAverage200 != null) {
//					if(symbol.startsWith("9")) { //大盘指数保存到j2cache
//						cache.evict("default", "ZS"+symbol);
//						cache.set("default", "ZS"+symbol, priceCompareAverage200);
//					}else {
//						//System.out.println(priceCompareAverage.toString());
//						//保存当前股票价格与均线比值
//						a = System.currentTimeMillis();
//						PriceCompAverage200 pkey = new PriceCompAverage200(priceCompareAverage200.getSymbol(), priceCompareAverage200.getStartDate(), priceCompareAverage200.getEndDate());
//						List<PriceCompAverage200> objs = iPriceCompAverage200Service.selectPriceCompAverage200List(pkey);//.selectByPrimaryKey(pkey);
//						if(objs.size()==0){
//							iPriceCompAverage200Service.insertPriceCompAverage200(priceCompareAverage200);
//						}else {
//							iPriceCompAverage200Service.updatePriceCompAverage200(priceCompareAverage200);
//						}
//						b = System.currentTimeMillis();
//						System.out.println("保存当前股票价格与均线比值耗时："+(b-a)/1000+"秒， "+(b-a)+"毫秒");
//					}
//				}
//				list200TradeData.clear();
//				list200TradeData = null;
//			}
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	private Map<String, Map<String, Object>> hqsinajs(String tempString) {
//
//		Map<String, Map<String, Object>> map_vol_price = new HashMap<String, Map<String, Object>>();
//		int jsq = 0;
//		boolean whileflag11 = true;
//
//		while (whileflag11) {
//
//			Map<String, Object> temp_net_price = new HashMap<String, Object>();
//			Map<String, Object> temp_net_vol = new HashMap<String, Object>();
//			Map<String, Object> temp_net_date = new HashMap<String, Object>();
//			Map<String, Object> temp_net_amount = new HashMap<String, Object>();
//			Map<String, Object> temp_net_open = new HashMap<String, Object>();
//			Map<String, Object> temp_net_high = new HashMap<String, Object>();
//			Map<String, Object> temp_net_low = new HashMap<String, Object>();
//
//			Document doc;
//
//			try {
//
//				doc = Jsoup.connect("http://hq.sinajs.cn/list=" + tempString).ignoreContentType(true).get();
//
//				String text = doc.body().text();
//				String hq[] = text.split(";");
//				for (String s : hq) {
//					// hq_str_sz000006="深振业Ａ,7.330,7.300,7.240,7.440,7.120,7.230,7.240,7879672,57568150.670,15500,7.230,3000,7.220,22400,7.210,174200,7.200,19100,7.190,25800,7.240,27000,7.250,14000,7.260,15100,7.270,25000,7.280,2016-05-13,16:30:03,00";
//					String oneSymbolHq[] = s.replaceAll("\"", "").replaceAll(" ", "").split("=");
//					if (oneSymbolHq.length == 1) {
//
//					} else {
//
//						String nameAndPrice[] = oneSymbolHq[1].split(",");
//						// String name = nameAndPrice[0]; 如：  深振业Ａ
//						BigDecimal price = new BigDecimal(nameAndPrice[3]);
//						BigDecimal vol = new BigDecimal(nameAndPrice[8]);
//						BigDecimal open = new BigDecimal(nameAndPrice[1]);
//						BigDecimal high = new BigDecimal(nameAndPrice[4]);
//						BigDecimal low = new BigDecimal(nameAndPrice[5]);
//
//						String symbol = oneSymbolHq[0].substring(12);
//
//						if (oneSymbolHq[0].contains("sz399001")){
//
//							symbol = "999001";
//
//							temp_net_vol.put(symbol, vol);
//
//						} else if (oneSymbolHq[0].contains("sh000001")){
//
//							symbol = "900001";
//
//							temp_net_vol.put(symbol, vol.multiply(new BigDecimal(100)));
//
//						} else if (oneSymbolHq[0].contains("sz399006")){
//
//							symbol = "999006";
//
//							temp_net_vol.put(symbol, vol);
//
//						} else {
//
//							temp_net_vol.put(symbol, vol);
//
//						}
//
//						temp_net_date.put(symbol, nameAndPrice[30]);
//						temp_net_amount.put(symbol,  new BigDecimal(nameAndPrice[9]));
//						temp_net_price.put(symbol, price);
//						temp_net_open.put(symbol, open);
//						temp_net_high.put(symbol, high);
//						temp_net_low.put(symbol, low);
//					}
//
//				}
//				// 下载成功后标志位更改，免得再次下载
//				whileflag11 = false;
//			} catch (java.net.SocketTimeoutException e1) {
//				e1.printStackTrace();
//			} catch (IOException e1) {
//				e1.printStackTrace();
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			map_vol_price.put("price",temp_net_price);
//			map_vol_price.put("vol",temp_net_vol);
//			map_vol_price.put("date",temp_net_date);
//			map_vol_price.put("amount",temp_net_amount);
//			map_vol_price.put("open",temp_net_open);
//			map_vol_price.put("high",temp_net_high);
//			map_vol_price.put("low",temp_net_low);
//
//			jsq++;
//			/*try {
//				Thread.sleep(3000);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}*/
//			if (jsq > 3) {
//				whileflag11 = false;
//				break;
//			}
//		}
//		return map_vol_price;
//	}
//
//	private void completeVolumeAndaragPrice(List<TRADEDATA200> list, Date today ) {
//		for (int i = 0; i < list.size(); i++) {
//			TRADEDATA200 tradeData = new TRADEDATA200();
//			BeanUtils.copyProperties(list.get(i), tradeData);
//			tradeData.setDatetime(list.get(i).getDatetime());
//			tradeData.setSymbol(list.get(i).getSymbol());
//			tradeData.setZhang(ZhangFun(list, i));
//			tradeData.setZhangfu(ZhangfuFun(list, i));
//			if(list.size() - i >=5)
//				tradeData.setVolume5(pingJunFun(list, 5, i, "volume"));
//			else
//				tradeData.setVolume5(null);
//			if(list.size() - i >=10)
//				tradeData.setVolume10(pingJunFun(list, 10, i, "volume"));
//			else
//				tradeData.setVolume10(null);
//			if(list.size() - i >=5)
//				tradeData.setAverageprice5(pingJunFun(list, 5, i, "closePrice"));
//			else
//				tradeData.setAverageprice5(null);
//			if(list.size() - i >=10)
//				tradeData.setAverageprice10(pingJunFun(list, 10, i, "closePrice"));
//			else
//				tradeData.setAverageprice10(null);
//			if(list.size() - i >=20)
//				tradeData.setAverageprice20(pingJunFun(list, 20, i, "closePrice"));
//			else{
//				tradeData.setAverageprice20(null);
//			}
//			if(list.size() - i >=60)
//				tradeData.setAverageprice60(pingJunFun(list, 60, i, "closePrice"));
//			else
//				tradeData.setAverageprice60(null);
//			BeanUtils.copyProperties(tradeData, list.get(i));
//			break;
//		}
//
//	}
//
//	private PriceCompAverage200 completePriceAverageComp(List<TRADEDATA200> list, TRADEDATA200 tradeDataKey) {
//		// 要求大于120日均线, 60日均线值在,60+才有数据
//		// MathContext mc = new MathContext(6, RoundingMode.HALF_UP);
//		PriceCompAverage200 pca = null;
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		//字符串转日期
//		Date dateParse = null;
//		try {
//			dateParse = sdf.parse("2000-12-12");
//			System.out.println(dateParse);
//		} catch (ParseException e) {
//			e.printStackTrace();
//		}
//		for (int i = 0; i < list.size() - 120; i++) {
//
//			TRADEDATA200 f = list.get(i + 0);
//			TRADEDATA200 e = list.get(i + 1);
//			TRADEDATA200 d = list.get(i + 2);
//			TRADEDATA200 c = list.get(i + 3);
//			TRADEDATA200 b = list.get(i + 4);
//			TRADEDATA200 a = list.get(i + 5);
//
//			if (f.getZhangfu().compareTo(new BigDecimal(10.5)) > 0
//					|| f.getZhangfu().compareTo(new BigDecimal(-10.5)) < 0) {
//				i = i + 60;
//				break;
//			}
//			pca = new PriceCompAverage200();
//			pca.setSymbol(tradeDataKey.getSymbol());
//			pca.setStartDate(a.getDatetime());
//			pca.setEndDate(f.getDatetime());
//
//			pca.setG1zhangfu(new BigDecimal(0));
//			pca.setF5a5(f.getAverageprice5().divide(a.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF5b5(f.getAverageprice5().divide(b.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF5c5(f.getAverageprice5().divide(c.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF5d5(f.getAverageprice5().divide(d.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF5e5(f.getAverageprice5().divide(e.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setF10a10(f.getAverageprice10().divide(a.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF10b10(f.getAverageprice10().divide(b.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF10c10(f.getAverageprice10().divide(c.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF10d10(f.getAverageprice10().divide(d.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF10e10(f.getAverageprice10().divide(e.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setF20a20(f.getAverageprice20().divide(a.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF20b20(f.getAverageprice20().divide(b.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF20c20(f.getAverageprice20().divide(c.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF20d20(f.getAverageprice20().divide(d.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF20e20(f.getAverageprice20().divide(e.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setF60a60(f.getAverageprice60().divide(a.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF60b60(f.getAverageprice60().divide(b.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF60c60(f.getAverageprice60().divide(c.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF60d60(f.getAverageprice60().divide(d.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF60e60(f.getAverageprice60().divide(e.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA1a5h(a.getHighprice().divide(a.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b5h(b.getHighprice().divide(b.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c5h(c.getHighprice().divide(c.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d5h(d.getHighprice().divide(d.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e5h(e.getHighprice().divide(e.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f5h(f.getHighprice().divide(f.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA1a5l(a.getLowprice().divide(a.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b5l(b.getLowprice().divide(b.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c5l(c.getLowprice().divide(c.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d5l(d.getLowprice().divide(d.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e5l(e.getLowprice().divide(e.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f5l(f.getLowprice().divide(f.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA1a5c(a.getCloseprice().divide(a.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b5c(b.getCloseprice().divide(b.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c5c(c.getCloseprice().divide(c.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d5c(d.getCloseprice().divide(d.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e5c(e.getCloseprice().divide(e.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f5c(f.getCloseprice().divide(f.getAverageprice5(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA1a10(a.getCloseprice().divide(a.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b10(b.getCloseprice().divide(b.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c10(c.getCloseprice().divide(c.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d10(d.getCloseprice().divide(d.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e10(e.getCloseprice().divide(e.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f10(f.getCloseprice().divide(f.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//
//
//			pca.setA1a20(a.getCloseprice().divide(a.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b20(b.getCloseprice().divide(b.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c20(c.getCloseprice().divide(c.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d20(d.getCloseprice().divide(d.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e20(e.getCloseprice().divide(e.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f20(f.getCloseprice().divide(f.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//
//
//			pca.setA1a60(a.getCloseprice().divide(a.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB1b60(b.getCloseprice().divide(b.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC1c60(c.getCloseprice().divide(c.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d60(d.getCloseprice().divide(d.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e60(e.getCloseprice().divide(e.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f60(f.getCloseprice().divide(f.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA5a10(a.getAverageprice5().divide(a.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB5b10(b.getAverageprice5().divide(b.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC5c10(c.getAverageprice5().divide(c.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD5d10(d.getAverageprice5().divide(d.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE5e10(e.getAverageprice5().divide(e.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF5f10(f.getAverageprice5().divide(f.getAverageprice10(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA10a20(a.getAverageprice10().divide(a.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB10b20(b.getAverageprice10().divide(b.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC10c20(c.getAverageprice10().divide(c.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD10d20(d.getAverageprice10().divide(d.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE10e20(e.getAverageprice10().divide(e.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF10f20(f.getAverageprice10().divide(f.getAverageprice20(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setA20a60(a.getAverageprice20().divide(a.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setB20b60(b.getAverageprice20().divide(b.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setC20c60(c.getAverageprice20().divide(c.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD20d60(d.getAverageprice20().divide(d.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE20e60(e.getAverageprice20().divide(e.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF20f60(f.getAverageprice20().divide(f.getAverageprice60(), 6, BigDecimal.ROUND_HALF_UP));
//
//			pca.setD1d10vol(d.getVolume().divide(d.getVolume10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e10vol(e.getVolume().divide(e.getVolume10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f10vol(f.getVolume().divide(f.getVolume10(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setD1d5vol(d.getVolume().divide(d.getVolume5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setE1e5vol(e.getVolume().divide(e.getVolume5(), 6, BigDecimal.ROUND_HALF_UP));
//			pca.setF1f5vol(f.getVolume().divide(f.getVolume5(), 6, BigDecimal.ROUND_HALF_UP));
//
//
//
//			pca.setAcompare(bijiao(a));
//			pca.setBcompare(bijiao(b));
//			pca.setCcompare(bijiao(c));
//			pca.setDcompare(bijiao(d));
//			pca.setEcompare(bijiao(e));
//			pca.setFcompare(bijiao(f));
//
//			pca.setA1zhangfu(a.getZhangfu());
//			pca.setB1zhangfu(b.getZhangfu());
//			pca.setC1zhangfu(c.getZhangfu());
//			pca.setD1zhangfu(d.getZhangfu());
//			pca.setE1zhangfu(e.getZhangfu());
//			pca.setF1zhangfu(f.getZhangfu());
//
//			pca.setB1date(b.getDatetime());
//			pca.setC1date(c.getDatetime());
//			pca.setD1date(d.getDatetime());
//			pca.setE1date(e.getDatetime());
//			pca.setF1date(f.getDatetime());
//
//			pca.setAopen(a.getDateopenprice());
//			pca.setAclose(a.getCloseprice());
//			pca.setAhigh(a.getHighprice());
//			pca.setAlow(a.getLowprice());
//			pca.setA5(a.getAverageprice5());
//			pca.setA10(a.getAverageprice10());
//			pca.setA20(a.getAverageprice20());
//			pca.setA60(a.getAverageprice60());
//
//			pca.setBopen(b.getDateopenprice());
//			pca.setBclose(b.getCloseprice());
//			pca.setBhigh(b.getHighprice());
//			pca.setBlow(b.getLowprice());
//			pca.setB5(b.getAverageprice5());
//			pca.setB10(b.getAverageprice10());
//			pca.setB20(b.getAverageprice20());
//			pca.setB60(b.getAverageprice60());
//
//			pca.setCopen(c.getDateopenprice());
//			pca.setCclose(c.getCloseprice());
//			pca.setChigh(c.getHighprice());
//			pca.setClow(c.getLowprice());
//			pca.setC5(c.getAverageprice5());
//			pca.setC10(c.getAverageprice10());
//			pca.setC20(c.getAverageprice20());
//			pca.setC60(c.getAverageprice60());
//
//			pca.setDopen(d.getDateopenprice());
//			pca.setDclose(d.getCloseprice());
//			pca.setDhigh(d.getHighprice());
//			pca.setDlow(d.getLowprice());
//			pca.setD5(d.getAverageprice5());
//			pca.setD10(d.getAverageprice10());
//			pca.setD20(d.getAverageprice20());
//			pca.setD60(d.getAverageprice60());
//
//			pca.setEopen(e.getDateopenprice());
//			pca.setEclose(e.getCloseprice());
//			pca.setEhigh(e.getHighprice());
//			pca.setElow(e.getLowprice());
//			pca.setE5(e.getAverageprice5());
//			pca.setE10(e.getAverageprice10());
//			pca.setE20(e.getAverageprice20());
//			pca.setE60(e.getAverageprice60());
//
//			pca.setFopen(f.getDateopenprice());
//			pca.setFclose(f.getCloseprice());
//			pca.setFhigh(f.getHighprice());
//			pca.setFlow(f.getLowprice());
//			pca.setF5(f.getAverageprice5());
//			pca.setF10(f.getAverageprice10());
//			pca.setF20(f.getAverageprice20());
//			pca.setF60(f.getAverageprice60());
//
//			pca.setCreateDate(dateParse);
//			break;
//		}
//		return pca;
//	}
//
//	/*
//	 * 通用计算平均值
//	 */
//	private BigDecimal pingJunFun(List<TRADEDATA200> ls, int size, int num, String volumeOrClosePrice) {
//		BigDecimal reback = new BigDecimal(0);
//		for (int i = num; i < (num + size); i++) {
//			if ("volume".equals(volumeOrClosePrice) && i < ls.size()) {
//				reback = reback.add(new BigDecimal(ls.get(i).getVolume().toString()));
//			} else if ("closePrice".equals(volumeOrClosePrice) && i < ls.size()) {
//				reback = reback.add(new BigDecimal(ls.get(i).getCloseprice().toString()));
//			}
//		}
//		return reback.divide(new BigDecimal(size), 2, BigDecimal.ROUND_HALF_UP);
//	}
//
//	/*
//	 * 通用计算差值
//	 */
//	private BigDecimal ZhangFun(List<TRADEDATA200> ls, int num) {
//		BigDecimal yesterDayPrice = new BigDecimal(0);
//		BigDecimal todayPrice = new BigDecimal(0);
//		if (num + 1 < ls.size()) {
//			todayPrice = new BigDecimal(ls.get(num).getCloseprice().toString());
//			yesterDayPrice = new BigDecimal(ls.get(num + 1).getCloseprice().toString());
//		}
//		return todayPrice.subtract(yesterDayPrice).setScale(2, BigDecimal.ROUND_HALF_UP);
//	}
//
//	/*
//	 * 通用计算涨幅
//	 */
//	private BigDecimal ZhangfuFun(List<TRADEDATA200> ls, int num) {
//		BigDecimal yesterDayPrice = new BigDecimal(0);
//		BigDecimal todayPrice = new BigDecimal(0);
//		BigDecimal result = new BigDecimal(0);
//		if (num + 1 < ls.size()) {
//			todayPrice = new BigDecimal(ls.get(num).getCloseprice().toString());
//			yesterDayPrice = new BigDecimal(ls.get(num + 1).getCloseprice().toString());
//			result = todayPrice.subtract(yesterDayPrice).divide(yesterDayPrice, 4, BigDecimal.ROUND_HALF_UP)
//					.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
//		}
//		return result;
//	}
//
//	private String bijiao(TRADEDATA200 td) {
//
//		BigDecimal a60 = td.getAverageprice60().setScale(2, BigDecimal.ROUND_HALF_UP);
//		BigDecimal a20 = td.getAverageprice20().setScale(2, BigDecimal.ROUND_HALF_UP);
//		BigDecimal a10 = td.getAverageprice10().setScale(2, BigDecimal.ROUND_HALF_UP);
//		BigDecimal a5 = td.getAverageprice5().setScale(2, BigDecimal.ROUND_HALF_UP);
//		//BigDecimal a1 = td.getCloseprice().setScale(2, BigDecimal.ROUND_HALF_UP);
//
//		List<NameAndValue> list = new ArrayList<NameAndValue>();
//		//list.add(new NameAndValue("1",a1));
//		list.add(new NameAndValue("5",a5));
//		list.add(new NameAndValue("60",a60));
//		list.add(new NameAndValue("10",a10));
//		list.add(new NameAndValue("20",a20));
//
//		Collections.sort(list);
//		StringBuffer sb = new StringBuffer();
//		for(int i = 0 ; i < list.size() - 1 ; i++) {
//			if(list.get(i).getValue() .compareTo( list.get(i+1).getValue()) < 0 ) {
//				sb.append(list.get(i).getName()).append("<");
//			}
//			if(list.get(i).getValue() .compareTo( list.get(i+1).getValue()) == 0 ) {
//				sb.append(list.get(i).getName()).append("=");
//			}
//			if(list.get(i).getValue() .compareTo( list.get(i+1).getValue()) > 0 ) {
//				sb.append(list.get(i).getName()).append(">");
//			}
//		}
//		sb.append(list.get(list.size()-1).getName());
//		return sb.toString()
//				.replace("20=10", "10=20")
//				.replace("60=10", "10=60")
////				.replace("5=1", "1=5")
////				.replace("10=1", "1=10")
////				.replace("20=1", "1=20")
////				.replace("60=1", "1=60")
//				.replace("10=5", "5=10")
//				.replace("20=5", "5=20")
//				.replace("60=5", "5=60")
//				.replace("60=20", "20=60");
//	}
//}
